package com.servlet;

import com.bean.*;
import com.service.FavoriteService;
import com.service.impl.FavoriteServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/FavoriteServlet.do")
public class FavoriteServlet extends BaseServlet{
    FavoriteService favoriteService=new FavoriteServiceImpl();

    /**
     * 添加收藏
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */

    protected void favoriteAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        Integer id = Integer.parseInt(request.getParameter("id"));
        Favorite favorite1 = new Favorite();
        favorite1.setVideoId(id);
        favorite1.setUserId(user.getId());
        favoriteService.addFav(favorite1);

//        List<FavoriteList> favoriteListList = favoriteService.queryFav(user.getId());
//        request.getSession().setAttribute("favoriteListList", favoriteListList);

        request.getRequestDispatcher("/single.jsp").forward(request, response);

    }


//删除收藏
    protected void favoritedele(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        favoriteService.seleteFav(Integer.parseInt(id));
        request.getRequestDispatcher("/PersonalCenter.jsp").forward(request, response);

//        List<FavoriteList> favoriteListList = favoriteService.queryFav(user.getId());
//        request.getSession().setAttribute("favoriteListList", favoriteListList);



    }
}
